<#assign className = table.className>
<#assign classNameLower = className?uncap_first>

<#assign classMapperName = classNameLower+"Mapper">
        package ${basepackage};

<#assign rsize = table.relationTables?size>

import ${modelPack}.${className};
import ${daoPack}.${className}Mapper;
import cn.wyd.ibase.constant.constant;
import cn.wyd.ibase.dto.ExceptionMessage;
import cn.wyd.ibase.dto.Message;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.Date;

/**
 * Created by wangYuDong on 2017/5/10.
 */
@Controller
@RequestMapping("/${classNameLower}")
public class ${className}Controller {
    @Resource
    private ${className}Mapper ${classMapperName};

    @ResponseBody
    @RequestMapping(value="/get",method = RequestMethod.GET)
    public Page<${className}> getUserList(Page<${className}> page){
        <#if (rsize>0)>
        page.setRecords( ${classMapperName}.selectMyPage(page,new EntityWrapper<${className}>()));
        <#else>
        page.setRecords( ${classMapperName}.selectPage(page,new EntityWrapper<${className}>()));
        </#if>
        return page;
    }

    @ResponseBody
    @RequestMapping(value = "/add",method = RequestMethod.POST)
    public Message ${classNameLower}Add(${className} ${classNameLower}){
        Integer i=${classMapperName}.insert(${classNameLower});
        if(i>0){
            return new Message("添加成功");
        }else{
            return new ExceptionMessage("添加失败",constant.ERROR_USER+constant.ERROR_CREATE);
        }
    }

    @ResponseBody
    @RequestMapping(value = "/{id}",method = RequestMethod.DELETE)
    public Message ${classNameLower}Delete(@PathVariable  Integer id){
        Integer i=${classMapperName}.deleteById(id);
        if(i>0){
            return new Message("删除成功");
        }else{
            return new ExceptionMessage("删除失败",constant.ERROR_USER+constant.ERROR_DELETE);
        }
    }

    @ResponseBody
    @RequestMapping(value = "/{id}",method =RequestMethod.PATCH)
    @ApiOperation(value="修改",httpMethod = "PATCH")
    public Message  ${classNameLower}Update(@PathVariable Integer id,${className} ${classNameLower}){
        ${classNameLower}.setId(id);
        Integer i=${classMapperName}.updateById(${classNameLower});
        if(i>0){
            return new Message("更新成功");
        }else{
            return new ExceptionMessage("更新失败",constant.ERROR_USER+constant.ERROR_UPDATE);
        }
    }
}
